package com.ay.weixin.fdc.boss.project.db;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lizar.db.ibatis.Dao;

import com.ay.weixin.fdc.boss.project.domain.FDCProject;

public class IbatisProjectDao extends Dao{
	
	public void insert(FDCProject project) throws SQLException{
		this.sqlMapper.insert("fdc_project.insert",project);
	}
	
	public void update(FDCProject project) throws SQLException{
		this.sqlMapper.update("fdc_project.update",project);
	}
	
	public boolean exists(long id) throws SQLException{
		Object obj=this.sqlMapper.queryForObject("fdc_project.exists",id);
		if(obj==null)return false;
		return true;
	}
	
	public int getMaxPos(long wxproject_id,long category) throws SQLException{
		Map<String,Long> keys=new HashMap<String,Long>();
		keys.put("wxproject_id",wxproject_id);
		keys.put("category",category+0l);
		Integer max=(Integer)this.sqlMapper.queryForObject("fdc_project.getMaxPos",keys);
		if(max==null){
			return 0;
		}
		return max+1;
	}
	
	
	
	public List<FDCProject> getAllByFront(long wxproject_id,int status) throws SQLException{
		Map<String,Object> keys=new HashMap<String,Object>();
		keys.put("wxproject_id",wxproject_id);
		keys.put("status",status);
		return (List<FDCProject>)this.sqlMapper.queryForList("fdc_project.getAllByFront",keys);
	}
	
	public List<FDCProject> getByCategoryByFront(long wxproject_id,int category,int status) throws SQLException{
		Map<String,Long> keys=new HashMap<String,Long>();
		keys.put("status",status+0l);
		keys.put("wxproject_id",wxproject_id);
		keys.put("category",category+0l);
		return (List<FDCProject>)this.sqlMapper.queryForList("fdc_project.getByCategoryByFront",keys);
	}
	
	public List<FDCProject> getByCategory(long wxproject_id,int category) throws SQLException{
		Map<String,Long> keys=new HashMap<String,Long>();
		keys.put("wxproject_id",wxproject_id);
		keys.put("category",category+0l);
		return (List<FDCProject>)this.sqlMapper.queryForList("fdc_project.getByCategory",keys);
	}
	
	public List<FDCProject> getAllByWxprojectId(long wxproject_id) throws SQLException{
		return (List<FDCProject>)this.sqlMapper.queryForList("fdc_project.getAllByWxprojectId",wxproject_id);
	}
	
	public FDCProject get(long id) throws SQLException{
		return (FDCProject)this.sqlMapper.queryForObject("fdc_project.get",id);
	}

	public void update_status(long id,int status,int category) throws SQLException{
		Map<String,Long> keys=new HashMap<String,Long>();
		keys.put("id",id);
		keys.put("status",status+0l);
		keys.put("category",category+0l);
		this.sqlMapper.update("fdc_project.update_status",keys);
	}
	
	public void delete(long id)throws SQLException{
		this.sqlMapper.delete("fdc_project.delete",id);
	}
	
}
